﻿using System;
using Epm.AppLogic.Framework;
using msBsc.Xsd.DataTds;
using System.Data;

namespace msBsc.AppLogic.DataAlc
{
    public class CBizEmployeeInfo : CustBizObject
    {
        private CDmDjkEmployeeInfo m_CDmDjkEmployeeInfo = new CDmDjkEmployeeInfo();
        private CDmDjkEmployeeInfo oDmDjkEmployeeInfo
        {
            get { return m_CDmDjkEmployeeInfo; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public CBizEmployeeInfo()
            : base()
        {
            this.DataObj = new CDbAccess();
            this.DataObj.Init(this.m_CDmDjkEmployeeInfo.DJK_EMPLOYEE_INFO);
            this.TableName = this.DataObj.TableName;
            this.DataObj.KeyField = this.DataObj.Fields["EMPLOYEE_INFO_ID"];
        }

        /// <summary>
        /// 新增记录前的处理
        /// </summary>
        /// <param name="drw">新增数据行</param>
        /// <returns>true/false</returns>
        /// <remarks>
        /// 生成ID值
        /// </remarks>
        protected override bool BeforeRowAdded(DataRow drw)
        {
            if (drw[this.KeyFieldName].ToString().Length < 10)
            {
                drw[this.KeyFieldName] = this.DataObj.NewID();
            }


            drw["EMPLOYEE_INFO_PWD"] = msBsc.AppLogic.Cfg.DesCry.encMe(drw["EMPLOYEE_INFO_PWD"].ToString(), "zbhpass");
            drw["EMPLOYEE_IS_DELETED"] = false;
            drw["EMPLOYEE_IS_DISPLAY"] = true;
            drw["EMPLOYEE_INVITATION_CODE"] = msBsc.SvRef.ApplicationConst.Const.GenerateStrId();

            drw["EMPLOYEE_WORK_STATUS"] = 1;

            return true;
        }

        /// <summary>
        /// 记录修改前检验
        /// </summary>
        /// <param name="drw">当前记录</param>
        /// <returns>>校验合法，返回值为true,否则返回false</returns>
        /// <remarks>
        /// ID不允许修改,并把此修改操作记录到BSE_MODIFY_HISTORY表中
        /// </remarks>
        protected override bool BeforeRowModified(DataRow drw)
        {
            //ID不容许修改
            if (drw[this.KeyFieldName].ToString() != drw[this.KeyFieldName, DataRowVersion.Original].ToString())
            {
                Exception e = new Exception(this.TableName + "表的主键" + this.KeyFieldName + "字段不允许被修改");
                throw e;
            }
            return true;
        }
        protected override bool BeforeRowDeletedR(DataRow drw)
        {
            //using (msBsc.AppLogic.DataAlc.CBizShpPageColumn objtem = new CBizShpPageColumn())
            //{
            //    DataSet ds = objtem.SelectByPageNo(this.GetRowStr(drw, KeyFieldName));
            //    for (int i = ds.Tables[0].Rows.Count - 1; i >= 0; i--)
            //    {
            //        ds.Tables[0].Rows[i].Delete();
            //    }
            //    objtem.Update(ds);
            //} 
            return true;
        }

        protected override bool AfterRowAdded(DataRow drw)
        {
            return true;
        }

        protected override bool AfterRowModified(DataRow drw)
        {
            return true;
        }

        protected override bool AfterRowDeletedR(DataRow drw)
        {
            return true;
        }

        //        public DataSet SelectForLogin(string strUserNo)
        //        {
        //            //实例化sql参数类
        //            CDbParmCollection parmCollection = new CDbParmCollection();
        //            //添加sql参数
        //            parmCollection.Add(new CDbParm("strUserNo", ParameterDirection.Input, EDbType.String, 36, strUserNo));
        //            DataSet ds = this.DataObj.QueryBySQL(@"SELECT A.EMPLOYEE_INFO_CODE,A.EMPLOYEE_INFO_NAME,A.EMPLOYEE_INFO_PWD
        //    FROM DJK_EMPLOYEE_INFO A
        //    WHERE A.EMPLOYEE_INFO_CODE=@strUserNo", parmCollection);
        //            ds.Tables[0].TableName = this.TableName;
        //            return ds;
        //        }

        /// <summary>
        /// 获取全部员工信息
        /// </summary>
        /// <returns></returns>
        public DataSet GetAllEmployee()
        {
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT EMPLOYEE_INVITATION_CODE,EMPLOYEE_INFO_NAME FROM DJK_EMPLOYEE_INFO");
            return ds;
        }


        public DataSet GetEmployeeInfoById(string employeeId)
        {
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("employeeId",ParameterDirection.Input,EDbType.String,36,employeeId.Replace("'","").Replace(",","','")));

            DataSet ds = this.DataObj.QueryBySQL(@"SELECT * FROM DJK_EMPLOYEE_INFO WHERE EMPLOYEE_INFO_ID= @employeeId",parmCollection);
            return ds;
        }
    }
}
